package trinnes.oliver.unimaas.smartpentalath.intelligence.features;

import trinnes.oliver.unimaas.smartpentalath.control.Game;
import trinnes.oliver.unimaas.smartpentalath.data.Cell;
import trinnes.oliver.unimaas.smartpentalath.data.Piece;

/**
 *
 * @author Oliver Trinnes
 */
public class FreeNeighborsFeature extends Feature
{

  public FreeNeighborsFeature(int weight)
  {
    super(weight);
  }

  @Override
  public int getValue(Game game, int move)
  {
    Cell cell = game.getBoard().getCells().get(move);
    int freeNeighbors = 0;
    if (cell.getPiece().equals(game.getCurrentPlayer().getPiece()))
      for (Cell neighbor : cell.getNeighbors())
        if (neighbor != null && neighbor.getPiece().equals(Piece.EMPTY))
          freeNeighbors++;
    return freeNeighbors;
  }
}
